<?php
$this->title = "修改用户";
?>
<div class="main">
	<div class="header">修改用户：<?=$userinfo['username']?></div>
	<div class="form-container">
		<form id="user-form" class="form-horizontal" action="<?=ROOT_URL?>user/usermodify" method="post">
			<input type="hidden" name="id" value="<?=$userinfo['id']?>">
			<div class="form-group">
				<label class="col-sm-4 control-label">修改密码</label>
				<div class="col-sm-4">
					<input id="pass" type="password" class="form-control" name="password">
				</div>
				<div class="errormsg col-sm-2" style="color:black">（如果不修改密码，请将此空留空）</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label">确认密码</label>
				<div class="col-sm-4">
					<input id="passag" type="password" class="form-control">
				</div>
				<div class="errormsg col-sm-2"></div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label">性别</label>
				<div class="col-sm-4">
					<select class="form-control" name="sex">
						<?php
						if($userinfo['sex'] == '男')
						{
							echo "<option value='男' selected>男</option><option value='女'>女</option>";
						}
						else{
							echo "<option value='男'>男</option><option value='女' selected>女</option>";
						}
						?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label">工作单位</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" name="company" value="<?=$userinfo['company']?>">
					
				</div>
				<div class="errormsg col-sm-2"></div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label">部门</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" name="department" value="<?=$userinfo['department']?>">
					
				</div>
				<div class="errormsg col-sm-2"></div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label">职务</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" name="job" value="<?=$userinfo['job']?>">
					
				</div>
				<div class="errormsg col-sm-2"></div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label">邮箱</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" name="email" value="<?=$userinfo['email']?>">
					
				</div>
				<div class="errormsg col-sm-2"></div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label">联系方式</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" name="cellphone" value="<?=$userinfo['cellphone']?>">
					
				</div>
				<div class="errormsg col-sm-2"></div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label">真实姓名</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" name="truename" value="<?=$userinfo['truename']?>"> 
					
				</div>
				<div class="errormsg col-sm-2"></div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label">会员级别</label>
				<div class="col-sm-4">
					<select class="form-control" name="type">
						<option value="2" <?php if($userinfo['usertype'] == '2') echo "selected"?>>文章编辑员</option>
						<option value="3" <?php if($userinfo['usertype'] == '3') echo "selected"?>>文章审核员</option>
						<option value="4" <?php if($userinfo['usertype'] == '4') echo "selected"?>>超级管理员</option>
						<option value="1" <?php if($userinfo['usertype'] == '1') echo "selected"?>>普通用户</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label">所属会员组</label>
				<div class="col-sm-4">
					<select id="sel_group" class="form-control" multiple style="height:<?=count($groups)*19+14?>px">
						<?php
						foreach ($groups as $key => $value) {
							if($value['userid'] == $userinfo['id'])
								echo "<option value=". $value['id'] ." selected>". $value['name'] ."</option>";
							else
								echo "<option value=". $value['id'] .">". $value['name'] ."</option>";
						}
						?>
					</select>
					<input id="groups" type="hidden" name="groups">
				</div>
				<div class="errormsg col-sm-2"></div>
			</div>
		 	<div class="form-group">
				<label class="col-sm-4 control-label"></label>
				<div class="col-sm-4">
					<input id="submitbtn" type="button" class="btn btn-primary col-sm-4" value="确定" style="margin-right:40px">
					<input id="goback" type="button" class="btn btn-danger col-sm-4" value="返回">
				</div>
			</div> 
		</form>
	</div>
<div>
<script type="text/javascript">
$("#submitbtn").click(function(){

	if($.trim($("#pass").val()) != $.trim($("#passag").val())){
		return ;
	}

	var groups = [];
	$("#sel_group option:selected").each(function(){
		groups.push($(this).val());
	});
	$("#groups").val(groups.join(","));
	
	$("#user-form").submit();
});

$("#pass,#passag").blur(function(){
	var pass = $.trim($("#pass").val());
	var passag = $.trim($("#passag").val());
	
	if(pass == passag){
		$("#passag").parent().siblings(".errormsg").text("");
	}
	else
	{
		$("#passag").parent().siblings(".errormsg").text("两次输入密码不一致");
	}
});

$("#goback").click(function(){
	if(confirm("确定返回吗")){
		window.location.href = "<?=ROOT_URL?>user";
	}
});

</script>
